namespace DiLu.Expansion.File.Configs;

/// <summary>
///     删除文件夹配置
/// </summary>
public abstract record DeleteFolderConfig
{
    /// <summary>
    ///     删除文件夹配置
    /// </summary>
    /// <param name="directoryFullPath">目录完整路径</param>
    protected DeleteFolderConfig(string directoryFullPath)
    {
        ArgumentException.ThrowIfNullOrWhiteSpace(directoryFullPath, nameof(directoryFullPath));
        directoryFullPath = directoryFullPath.Replace('\\', '/').Trim();
        var rootPath = Path.GetPathRoot(directoryFullPath);
        ArgumentException.ThrowIfNullOrWhiteSpace(rootPath, nameof(rootPath));
        if (new DriveInfo(rootPath).DriveType == DriveType.Unknown) throw new ArgumentException("目录与系统目录不匹配");

        DirectoryFullPath = directoryFullPath.Trim();
    }

    /// <summary>
    ///     获取文件流配置
    /// </summary>
    /// <param name="rootDirectory">根目录</param>
    /// <param name="fileGroupName">文件分组名称</param>
    /// <param name="directoryRelativePath">目录相对路径</param>
    protected DeleteFolderConfig(string rootDirectory, string fileGroupName, string directoryRelativePath)
    {
        ArgumentException.ThrowIfNullOrWhiteSpace(rootDirectory, nameof(rootDirectory));
        rootDirectory = rootDirectory.Replace('\\', '/').Trim();
        var rootPath = Path.GetPathRoot(rootDirectory);
        ArgumentException.ThrowIfNullOrWhiteSpace(rootPath, nameof(rootPath));
        if (new DriveInfo(rootPath).DriveType == DriveType.Unknown) throw new ArgumentException("目录与系统目录不匹配");

        RootDirectory = rootDirectory;
        FileGroupName = $"{fileGroupName?.Trim()}";
        DirectoryRelativePath = $"{directoryRelativePath.Trim()}";
        DirectoryFullPath = Path.Combine(RootDirectory, FileGroupName, DirectoryRelativePath);
    }

    /// <summary>
    ///     根目录
    /// </summary>
    public string RootDirectory { get; }

    /// <summary>
    ///     文件分组名称
    /// </summary>
    public string FileGroupName { get; }

    /// <summary>
    ///     目录相对路径
    /// </summary>
    public string DirectoryRelativePath { get; }

    /// <summary>
    ///     目录完整路径
    /// </summary>
    public string DirectoryFullPath { get; }
}